package parser

import (
	"learn/crawler/engine"
	"regexp"
)

var categoryRe = regexp.MustCompile(`<a href="(https://www.lagou.com/zhaopin/[^/]+/)"[^>]*>([^<]+)</a>`)

func ParseCategory(contents []byte) engine.ParseResult {
	matches := categoryRe.FindAllSubmatch(contents, -1)
	result := engine.ParseResult{}

	for _, m := range matches {
		url := string(m[1])

		result.Requests = append(result.Requests, engine.Request{
			Url:        url,
			ParserFunc: JobListParse,
		})
	}

	return result
}
